#include "solverintersection.h"

SolverIntersection::SolverIntersection(const map<string, vector<cache> >& workingDataSet) : Solver(workingDataSet)
{
}

void SolverIntersection::findCommonCaches(void)
{
    bool firstTime = true;

    for (std::map<string, vector<cache> >::const_iterator mapIt = dataSet.begin(); mapIt
            != dataSet.end(); ++mapIt)
    {
        // If this is the first pass, just load the result set with this vector
        if (firstTime)
        {
            commonCaches = mapIt->second;
            firstTime = false;
        }
        else
        {
            vector<cache> tempSet = commonCaches;
            vector<cache> tempResultSet;
            set_intersection(mapIt->second.begin(), mapIt->second.end(),
                             tempSet.begin(), tempSet.end(),
                             back_inserter(tempResultSet), cacheSorter);

            commonCaches = tempResultSet;
        }
    }
}

vector<cache>& SolverIntersection::getCommonCaches()
{
    return commonCaches;
}

